import Dl from '@/views/dl.vue'
import Lb from '@/views/lb.vue'
import Ss from '@/views/ss.vue'
import Wgq1 from '@/views/wgq/wgq1.vue'
import Wgq2 from '@/views/wgq/wgq2.vue'
import Wgq3 from '@/views/wgq/wgq3.vue'
import Wgq4 from '@/views/wgq/wgq4.vue'
import Wgq5 from '@/views/wgq/wgq5.vue'
import Xqy from '@/views/xqy.vue'
import Zc from '@/views/zc.vue'
import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/wgq1/wgq2' },
    {
      path: '/wgq1',
      component: Wgq1,
      children: [
        {
          path: 'wgq2',
          component: Wgq2,
        },
        {
          path: 'wgq3',
          component: Wgq3,
        },
        {
          path: 'wgq4',
          component: Wgq4,
        },
        {
          path: 'wgq5',
          component: Wgq5,
        },
      ]
    },
    {
      path: '/ss',
      component: Ss,
    },
    {
      path: '/xqy/:goods_id',
      component: Xqy,
    },
    {
      path: '/lb/:cat_name',
      component: Lb,
    },
    {
      path: '/zc',
      component: Zc,
    },
    {
      path: '/dl',
      component: Dl,
    },
  ],
})
router.beforeEach((to, from, next) => {
  if(to.fullPath=='/wgq1/wgq4'||to.fullPath=='/wgq1/wgq5'){
    let token=localStorage.getItem('token')
    if(token){
      next()
    }
    else{
      next('/zc')
    }
  }
  else{
    next()
  }
})
export default router
